<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Bugsby Tracking</title>
<link href="stylesheets/group1Site.css" rel="stylesheet" type="text/css">
<link rel="icon" href="graphics/favicon.ico" type="image/x-icon">
<link rel="shortcut icon" href="graphics/favicon.ico" type="image/x-icon">
<script src="scripts/jquery-1.7.1.js"></script>
<script src="scripts/imageSwap.js"></script>
</head>

<body>
<div id="wrapper">

  <div id="banner">
    <img src="graphics/banner1.png" height="90" width="730" alt="bugsby logo">
  </div>
<div id="leftcolumn">
    <div id="nav">
    	<ul>
      		<li><a href="index.html"><img src="graphics/home.ico" border=0 height="36" width="36" alt="home icon">&nbsp;Home</a></li>
      		<li><a href="buglist.php"><img src="graphics/Spider.ico" border=0 height="36" width="36" alt="bug list icon">&nbsp;Bug List</a></li>
      		<li><a href="buginfo.html"><img src="graphics/info.png" border=0 height="36" width="36" alt="Info">&nbsp;Info</a></li>
      		<li><a href="bugmail.html"><img src="graphics/Gmail.png" border=0 height="36" width="36" alt="feedback icon">&nbsp;Contact</a></li>
    	</ul>
  	</div><!-- End Nav id -->
</div><!-- End leftcolumn -->


<div id="content">
<h1>Contact Bugsby</h1>

<p class="standardText">&nbsp;</p>
<?php
//declare and initialize globals
$fullnameValid = 0;
$zipcodeValid = 0;
$emailValid = 0;
$sendEmail = 0;
//First Validate that form has been submitted
if ($_POST['submitted']== 1) {  
// VALIDATE NAME /////////////////////////////////////////////////////////////////////
	//Check that the user entered a name
     if ($_POST['fullname']){  
	 	//Assign the name a variable
        $fullname = $_POST['fullname']; 
		//Check if name contains a numeric value
		if (preg_match('#[0-9]#',$fullname)){
			//Print msg indicating name is numeric
			echo '<h2>Improperly formatted name.</h2>';
			echo '<p> A valid full name must not contain numeric values</p>';
								  }
		//is name is not numeric continue with length check
		else{
			if(is_string($fullname)){
			//Assign length of string
			$nameLen = strlen($fullname);
			//Check if name is less than four characters
			if($nameLen < 2){
				//msg indicating string is too small
				echo '<h2>Improperly formatted name.</h2>';
				echo '<p> A valid full name must have more than 2 characters.</p>';
							}
			//if full name does not contain numeric values and correct size set flag indicating valid
			else{
				$fullnameValid = 1;
				}
									}
		else{
			'<h2> Name can not include numbers </h2>';
		}
     }  
	 }
	 //else name field is blank
	else{  
		 //response for blank name field
         echo '<h2>Name can not be blank.</h2>'; 
		 echo '<p>Please enter your full name, thank you.</p>';  
     }  
	 
// VALIDATE ZIPCODE /////////////////////////////////////////////////////////////////////
	  if ($_POST['zipcode']){  
	  	//if zip is numeric
        $zipcode = $_POST['zipcode']; 
		//test is zip contains all numeric values
		if(is_numeric($zipcode)){
			//test if zip is the correct length: 5 digits
			if(strlen($zipcode)< 5 || strlen($zipcode)>5){
				echo '<h2>Zipcode is not the required length</h2>';
				echo '<p>Please ensure the zipcode consists of 5 numeric values</p>';
			}
			//Set for valid zip
			else{
				$zipcodeValid = 1;
			}
		}
		//if zipcode is not all numeric
		else{
			echo '<h2>Zipcode must be a numeric value</h2>';
			echo '<p>Please enter a 5-digit zipcode </p>';	
		}
     }  
	 //if zipcode is blank
     else{  
         echo '<h2>Zipcode can not be blank.</h2>'; 
		 echo '<p>Please enter a valid zipcode, thank you.</p>'; 
     }  
	 
// VALIDATE EMAIL /////////////////////////////////////////////////////////////////////
	  //Email field contains values	 
	  if ($_POST['email']){  
	  	//Assign email variable
        $email = $_POST['email']; 
		
		if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    		//echo "This (email_a) email address is considered valid.";
			$emailValid = 1;
			}
			else{
				echo '<h2>Improperly formatted email.</h2>';	
			    echo '<p>Please enter a valid email address, thank you.</p>'; 
			}
		
	  						}//end initial email if 
	  
     else{  
	 	//If email is blank
		 echo '<h2>Email can not be blank.</h2>'; 
		 echo '<p>Please enter your email address, thank you.</p>'; 
     }  
	 

	//if fullname, zipcode, and email pass validation test here
	 if($zipcodeValid == 1 && $fullnameValid == 1 && $emailValid == 1){
		//Complete validation msg
		
		echo'<h2> Thank You for Your Support! </h2>';
		echo'<p> Your information was successfully processed and sent to the
		Bugsby Administrators.</p>';
		echo '<p> Again, your feedback is greatly appreciated and will improve the free use bug tracking community. Thank you for for taking the time to better the Bugsby experience!
        </p>';
		
		$sendEmail = 1;
	 }
	 
	 //Send Email with information from form
	 if($sendEmail == 1){
		$now = getdate();
		$to = "cs633group1@gmail.com";
		$subject = "Bugsby User Form Submitted";
		$from = $_POST['email'];
		$headers = "From: $from";
		$message = "From: ". $_POST['fullname'] . " Zip Code: " . $_POST['zipcode'] . " Comments: " . $_POST['siteComments'] . " Information successfully submitted: " . $now[mday] . " " . $now[month] . " " . $now[year] . " " . $now[hours] . ":" . $now[minutes] . ":" . $now[seconds];
		mail($to,$subject,$message,$headers);
		echo "Information successfully submitted: " . $now[mday] . " " . $now[month] . " " . $now[year] . " " . $now[hours] . ":" . $now[minutes] . ":" . $now[seconds];
	 }
	   
}//End inital bracket for submitted
?>
</div> <!-- End content -->
        
<hr>
<div id="navGraphics">
<h2>Click on a Graphic to Choose an Option:</h2>
<table width="800" border="0">
  <tr>
    <td><a href="index.html"><img src="graphics/home.png" border=0 height="128" width="128" alt="homepage icon" rel="graphics/homeRed.png" class="rollover" /></a></td>
    <td><a href="buglist.php"><img src="graphics/Spider.png" border=0 height="128" width="128" alt="view bug icon" rel="graphics/SpiderRed.png" class="rollover" /></a></td>
     <td><a href="buginfo.html"><img src="graphics/info.png" border=0 height="128" width="128" alt="information icon" rel="graphics/infoRed.png" class="rollover" /></a></td>
  </tr>
  <tr>
    <td class="standardText">Bugsby Home</td>
    <td class="standardText">View Bug Report</td>
    <td class="standardText">Information</td>
  </tr>
</table>

</div>
	<div id="footer">
	Site Content: <a href="mailto:cs633group1@gmail.com">CS633 Group 1</a> 
	</div><!-- End Footer -->
</div><!-- End Wrapper -->
</body>
</html>
